<?php

$Username = $_REQUEST['Username'];
$UserType = $_REQUEST['UserType'];
$Password = $_REQUEST['Password'];
$StaffName = $_REQUEST['StaffName'];
$ContactNumber = intval($_REQUEST['ContactNumber']);
$Email = $_REQUEST['Email'];
$centreId = intval($_REQUEST['CentreName']);

$passHashed = md5($Password); 
//$pass = substr($Password, 0, 7); 
include 'conn.php';

if($centreId!= 0){

	$sql = "insert into user(Username,Password,UserType,StaffName,CentreId,ContactNumber,Email) values('$Username','$passHashed','$UserType','$StaffName','$centreId','$ContactNumber','$Email')";
	$result = mysql_query($sql);
	if ($result){
		echo json_encode(array('success'=>true));
	} 
        else {
		print '<script type="text/javascript">';
		print 'alert("User cannot be created, please check the information entered!")';
		print '</script>';
	}
}
else{
	$sql = "insert into user(Username,Password,UserType,StaffName,CentreId,ContactNumber,Email) values('$Username','$passHashed','$UserType','$StaffName',NULL,'$ContactNumber','$Email')";
	$result = mysql_query($sql);
	if ($result){
		echo json_encode(array('success'=>true));
	} 
        else {
		print '<script type="text/javascript">';
		print 'alert("User cannot be created, please check the information entered!")';
		print '</script>';
	}
}
?>